#subset on urban municipalities
brazil_data_metro <- 
  brazil_data %>%
  filter(urb == 1) %>%
  filter(metro_area == 1)

brazil_data_non_metro <- 
  brazil_data %>%
  filter(urb == 1) %>%
  filter(metro_area == 0)

#metro
doc_mod_brazil <- lm(prop_doctos ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_metro)
teacher_mod_brazil <- lm(teachers_prop ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_metro)
comm_mod_brazil <- lm(prop_comm_health ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_metro)
schools_mod_brazil <- lm(schools_prop ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_metro)
elec_mod_brazil <- lm(electr_share_2010 ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_metro)
water_mod_brazil <- lm(piped_water_share_2010 ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_metro)

#non metro
doc_mod_brazil_non <- lm(prop_doctos ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_non_metro)
teacher_mod_brazil_non <- lm(teachers_prop ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_non_metro)
comm_mod_brazil_non <- lm(prop_comm_health ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_non_metro)
schools_mod_brazil_non <- lm(schools_prop ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_non_metro)
elec_mod_brazil_non <- lm(electr_share_2010 ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_non_metro)
water_mod_brazil_non <- lm(piped_water_share_2010 ~ log(pop) + pop_growth + density + div_index + avg_salary_mo_2010 + ill_rate_2010 + elec_index + align, data = brazil_data_non_metro)


table <- list(comm_mod_brazil,comm_mod_brazil_non, 
              schools_mod_brazil,schools_mod_brazil_non, 
              doc_mod_brazil,doc_mod_brazil_non,
              teacher_mod_brazil, teacher_mod_brazil_non,
              elec_mod_brazil,elec_mod_brazil_non,
              water_mod_brazil, water_mod_brazil_non)

table <- stargazer(table,
                   type = "html",
                   label = 'tab:brazil_metro',
                   title = "Relationship Between City Size and Public Goods, Brazil, Metro Split Sample",
                   column.separate = c(2, 2, 2, 2, 2, 2),
                   column.labels = c("Community Health Centers", "Schools", "Doctors", "Teachers",  "Eletricity Access", "Water Acess"),
                   multicolumn = T,
                   digits = 2,
                   dep.var.labels.include = F,
                   covariate.labels = c("City Size (log(population))", "Growth (\\%, 2001-2011)",
                                        "Density (1000/km2)", "Racial Diversity Index", "Average Monthly Income", 
                                        "Illiteracy Rate",
                                        "Electoral Competition Index","Partisan Alignment (0/1)"),
                   star.cutoffs = c(0.05, 0.01, 0.001),
                   keep.stat = c("n"),
                   notes = NULL,
                   add.lines = list(c("Cluster SE?", rep("No", 12)),
                                    c("Metro Area?", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No", "Yes", "No"))
                   
)




cat(table, sep = '\n', file = "./_4_outputs/table_oa_iii.htm")

